<template>
  <div>
    <v-title></v-title>
    <p>
      账 号：
      <input type="text" v-model="user.phone" placeholder="请输入手机号" />
    </p>
    <p>
      昵 称：
      <input type="text" v-model="user.nickname" placeholder="请输入昵称" />
    </p>
    <p>
      密 码：
      <input type="text" v-model="user.password" placeholder="请输入密码" />
    </p>
    <p>
      <button @click="goRegister">注册</button>
    </p>
  </div>
</template>
  
  <script>
  import {register} from "../request/api.js"
export default {
  data() {
    return {
      user: {
        phone: "",
        nickname: "",
        password: ""
      }
    };
  },

  methods: {
    goRegister() {
      //1.简单的输入判断
      if (!this.user.phone || !this.user.nickname || !this.user.password) {
        alert("请输入必要参数");
        return;
      }

      //2.提交数据到服务器，进行注册
      register(this.user)
        .then(res => {
           if(res.data.code == 200){
            //注册成功
            alert("注册成功，现在去登录！");
            this.$router.push("/login");
           }else{
             alert(res.data.msg)
           }
        })
        .catch(err => {
          console.log(err);
        });
    }
  }
};
</script>
  
<style scoped>
p {
  margin: 20px;
}
</style>